package com.lsmo.android.util;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

/**
 * 
 * @author SYX
 * @类描述： ArrayList适配器                                             
 * @项目名称：carfans     
 * @类名称：ArrayListAdapter                    
 * @修改时间：    
 * @修改备注：   
 * @param <T>
 */
public abstract class ArrayListAdapter<T> extends BaseAdapter {

	protected Context mContext;
	protected ArrayList<T> mList;
	protected ListView mListView;
	  
	
	public ArrayListAdapter(Context context){
		this.mContext = context;
	}
	
	@Override
	public int getCount() {
		if(mList != null)
			return mList.size();
		else
			return 0;
	}

	@Override
	public Object getItem(int position) {
		return mList == null ? null : mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	abstract public View getView(int position, View convertView, ViewGroup parent);
	
	public void setList(T[] paramArrayOfT)
	{
		ArrayList<T> arrayList = new ArrayList<T>(paramArrayOfT.length);  
		for (T t : paramArrayOfT) {  
			arrayList.add(t);  
		}  
		setList(arrayList);
	}
    
	public ArrayList<T> getList(){
		return mList;	
	}
	
	public void setList(ArrayList<T> paramArrayList){
		this.mList = paramArrayList;
	    notifyDataSetChanged();
	}
	
	public ListView getListView(){
		return mListView;
	}
	
    public void setListView(ListView paramListView)
	{
	   this.mListView = paramListView;
	}

}
